package com.zsr.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.zsr.example.config.annotation.OptLog;
import com.zsr.example.entity.EduCourse;
import com.zsr.example.service.EduCommentService;
import com.zsr.example.util.CommonUtil;
import com.zsr.example.util.PageUtil;
import com.zsr.example.vo.CommentReq;
import com.zsr.example.vo.CommentVo;
import org.apache.commons.collections4.ListUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zsr.example.util.constants.SysLogConstants.DELETE;
import static com.zsr.example.util.constants.SysLogConstants.UPDATE;

/**
 * 后台评论
 *
 * @author zhousiren
 * @date 2022/3/23 22:36
 */
@RestController
@RequestMapping("/comment")
public class EduCommentController {
    @Autowired
    private EduCommentService commentService;

    @PostMapping("getList")
    public JSONObject getChapterVideo(
            @RequestBody(required = false) CommentReq commentReq) {
        List<CommentVo> list = commentService.getListByTargetId(commentReq);
        List<CommentVo> records = PageUtil.build(commentReq.getPageNum(), commentReq.getPageSize(), list);
        return CommonUtil.successPage(list.size(), records);
    }

    @OptLog(optType = DELETE,optDesc = "删除评论")
    @PostMapping("batchDel")
    public JSONObject batchDel(List<String> commentIds) {
        commentService.removeByIds(commentIds);
        return CommonUtil.successJson();
    }
}
